/**
  ******************************************************************************
  * @file     SD93F115B_pwm.h
  * @author   TEST TEAM 												    	
  * @version  v0															    	
  * @date     Septemper 2022												    	
  * @brief
  *
  * Copyright (C) 2022  Hangzhou SDIC Microelectronics Co., Ltd
**********************************************************************************/

/* Define to prevent recursive inclusion */

#ifndef __SD93F115B_PWM_H
#define __SD93F115B_PWM_H

#ifdef __cplusplus
 extern "C" {
#endif

/****************Includes*************************/
#include "SD93F115B.h"


/**********************The group of PWM/PDM****************************/
#define IS_PWM_ALL_PERIPH(PERIPH) (((PERIPH) == PWM0)||((PERIPH) == PWM1))


#define PWM_Mode                  ((uint8_t) 0x00)	
#define	PDM_Mode                  PWM_CR_PMSEL

#define IS_PWM_PDM_Mode(Mode) (((Mode) ==PWM_Mode)||((Mode) == PDM_Mode)) 

/******************************************************/
typedef struct
{
  uint8_t PWM_PDM_Mode;           		            //选择输出PWM或PDM 
  
  FunctionalState PWM_WaveMode;    				    //设置PWM占空比期间输出电平状态
 
  uint16_t PWM_DutyCycle;     					    //设置PWM占空比

  uint16_t PWM_Period;     						    //设置PWM周期
  
  uint16_t PDM_DATA;                                //设置PDM数据寄存器

}PWM_InitTypeDef ;


/***************PWM Duty Cycle****************************/
#define IS_PWM_DutyCycle(DutyCycle) (((DutyCycle) >=0x0000)|| ((DutyCycle) <= 0xffff)) 

/*****************PWM Period******************************/
#define IS_PWM_Period(Period) (((Period)==0x0000 )|| ((Period) <= 0xffff )) 

/* Exported types ------------------------------------------------------------*/
void PWM_PDM_DeInit(PWM_TypeDef * PWMx);                                                //PWM/PDM恢复为上电默认值

void PWM_PDM_Init(PWM_TypeDef * PWMx,PWM_InitTypeDef* PWM_InitStruct);                  //初始化PWM功能
void PWM_PDM_Cmd(PWM_TypeDef * PWMx,FunctionalState NewState);                          //使能PWM/PDM输出

void PWM_PDM_ModeConfig(PWM_TypeDef * PWMx,uint8_t PWM_PDM_Mode);                       //配置PWM/PDM的工作模式，如PWM模式，还是PDM模式

void PWM_WaveModeCmd(PWM_TypeDef * PWMx,FunctionalState NewState);                      //使能PWMx占空比期间输出低电平，占空比溢出后输出高电平																					     
void PWM_SetDutyCycle(PWM_TypeDef * PWMx,uint16_t PWM_DutyCycle);                       //设置PWM的占空比
void PWM_SetPeriod(PWM_TypeDef * PWMx,uint16_t PWM_Period);                             //设置PWM的周期

void PDM_SetInputData(PWM_TypeDef * PWMx,uint16_t PDM_DATA);                            //设置PDM输入数据，以调整PDM的脉冲

void PWM_ITCmd(PWM_TypeDef * PWMx ,FunctionalState NewState);                           //使能PWM周期溢出中断功能
ITStatus PWM_GetITStatus(PWM_TypeDef * PWMx);                                           //获取PWM周期溢出中断标志位
void PWM_ClearITStatus(PWM_TypeDef * PWMx);                                             //清除PWM周期溢出中断标志位

#ifdef __cplusplus
}
#endif

#endif /* __SD93F115B_PWM_H */

/**********************************END OF FILE*********************************/